home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWSelect.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.0 KB  |  301 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSelect.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWSELECT_H
  13. #include "FWSelect.h"
  14. #endif
  15.  
  16. #ifndef FWCONTNT_H
  17. #include "FWContnt.h"
  18. #endif
  19.  
  20. #ifndef FWUTIL_H
  21. #include "FWUtil.h"
  22. #endif
  23.  
  24. #ifndef FWPRESEN_H
  25. #include "FWPresen.h"
  26. #endif
  27.  
  28. #ifndef FWPART_H
  29. #include "FWPart.h"
  30. #endif
  31.  
  32. #ifndef FWCLNINF_H
  33. #include "FWClnInf.h"
  34. #endif
  35.  
  36. #ifndef FWFRAME_H
  37. #include "FWFrame.h"
  38. #endif
  39.  
  40. #ifndef FWGRUTIL_H
  41. #include "FWGrUtil.h"
  42. #endif
  43.  
  44. #ifndef FWLNKMGR_H
  45. #include "FWLnkMgr.h"
  46. #endif
  47.  
  48. // ----- OS Layer Includes -----
  49.  
  50. #ifndef FWODGEOM_H
  51. #include "FWODGeom.h"
  52. #endif
  53.  
  54. #ifndef FWEVENT_H
  55. #include "FWEvent.h"
  56. #endif
  57.  
  58. #ifndef SLODFSTR_K
  59. #include "SLODFStr.k"
  60. #endif
  61.  
  62. // ----- OpenDoc Includes -----
  63.  
  64. #ifndef SOM_ODStorageUnit_xh
  65. #include <StorageU.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODSession_xh
  69. #include <ODSessn.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODShape_xh
  73. #include <Shape.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODFacet_xh
  77. #include <Facet.xh>
  78. #endif
  79.  
  80. #ifndef SOM_Module_OpenDoc_StdProps_defined
  81. #include <StdProps.xh>
  82. #endif
  83.  
  84. //========================================================================================
  85. // RunTime Info
  86. //========================================================================================
  87.  
  88. #ifdef FW_BUILD_MAC
  89. #pragma segment FWFrameworkSelection
  90. #endif
  91.  
  92. FW_DEFINE_AUTO(FW_CSelection)
  93.  
  94. //========================================================================================
  95. //    class FW_CSelection
  96. //========================================================================================
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    FW_CSelection::FW_CSelection
  100. //----------------------------------------------------------------------------------------
  101.  
  102. FW_CSelection::FW_CSelection(Environment* ev, FW_Boolean allowLinkSource, FW_Boolean allowLink) :
  103.     fPresentation(NULL),
  104.     fAllowLinkSource(allowLinkSource),
  105.     fAllowLink(allowLink)
  106. {
  107. FW_UNUSED(ev);
  108.     FW_END_CONSTRUCTOR
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. //    FW_CSelection::~FW_CSelection
  113. //----------------------------------------------------------------------------------------
  114.  
  115. FW_CSelection::~FW_CSelection()
  116. {
  117.     FW_START_DESTRUCTOR
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CSelection::AcquireSelectionOutline
  122. //----------------------------------------------------------------------------------------
  123. // By default just outline the shape returned by AcquireSelectionShape
  124.  
  125. ODShape* FW_CSelection::AcquireSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  126. {
  127.     FW_CAcquiredODShape outline = FW_CopyAndRelease(ev, AcquireSelectionShape(ev, facet, frame));
  128.     
  129.     if (!outline->IsEmpty(ev))
  130.         ::FW_OutlineODShape(ev, outline, FW_kFixedPos1);
  131.     
  132.     return outline.Orphan();
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_CSelection::IsSelectionLinkable
  137. //----------------------------------------------------------------------------------------
  138.  
  139. FW_Boolean FW_CSelection::IsSelectionLinkable(Environment* ev)
  140. {
  141. FW_UNUSED(ev);
  142.     return fAllowLinkSource;
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CSelection::GetPart
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CPart* FW_CSelection::GetPart(Environment *ev) const
  150. {
  151.     FW_ASSERT(fPresentation != NULL);
  152.     return fPresentation->GetPart(ev);
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_CSelection::IsMouseInDraggableItem
  157. //----------------------------------------------------------------------------------------
  158.  
  159. FW_Boolean FW_CSelection::IsMouseInDraggableItem(Environment* ev, 
  160.                                                 FW_CFrame* frame, 
  161.                                                 const FW_CMouseEvent& theMouseEvent, 
  162.                                                 FW_Boolean inBackground)
  163. {
  164. FW_UNUSED(inBackground);
  165.     if (IsEmpty(ev))
  166.         return FALSE;
  167.         
  168.     FW_CAcquiredODShape selectionShape = AcquireSelectionShape(ev, 
  169.                                                             theMouseEvent.GetFacet(ev), 
  170.                                                             frame);
  171.     
  172.     FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  173.     frame->GetContentView(ev)->FrameToViewContent(ev, where);
  174.     
  175.     ODPoint odWhere = where;
  176.     return selectionShape->ContainsPoint(ev, &odWhere);        
  177. }
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //    FW_CSelection::UpdateSelectionOnMouseDown
  181. //----------------------------------------------------------------------------------------
  182.  
  183. void FW_CSelection::UpdateSelectionOnMouseDown(Environment* ev, 
  184.                                             const FW_CMouseEvent& mouseEvent,
  185.                                             ODFacet* embeddedFacet,
  186.                                             FW_Boolean inEmbeddedFrameBorder,
  187.                                             FW_Boolean inBackground)
  188. {
  189. FW_UNUSED(ev);
  190. FW_UNUSED(mouseEvent);
  191. FW_UNUSED(embeddedFacet);
  192. FW_UNUSED(inEmbeddedFrameBorder);
  193. FW_UNUSED(inBackground);
  194.     // Don't do anything
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. //    FW_CSelection::AcquireSelectionShape
  199. //----------------------------------------------------------------------------------------
  200.  
  201. ODShape* FW_CSelection::AcquireSelectionShape(Environment* ev,  
  202.                                             ODFacet* facet,  
  203.                                             FW_CFrame* frame)
  204. {
  205. FW_UNUSED(frame);
  206.  
  207.     return facet->AcquireActiveShape(ev, NULL);
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CSelection::CanPasteAsLink
  212. //----------------------------------------------------------------------------------------
  213. FW_Boolean FW_CSelection::CanPasteAsLink(Environment* ev, 
  214.                                         ODPasteAsMergeSetting& setting,
  215.                                         ODStorageUnit* su)
  216. {
  217. FW_UNUSED(ev);
  218. FW_UNUSED(su);
  219.     // Return value specifies whether this selection can become a destination link.
  220.     // Also specify default settings for the PasteAs dialog: 
  221.     //    kODPasteAsMergeOnly, kODPasteAsEmbedOnly, kODPasteAsMerge, kODPasteAsEmbed
  222.     setting = kODPasteAsMergeOnly;    // default is no embedding
  223.  
  224.     return fAllowLink;
  225. }
  226.  
  227. //----------------------------------------------------------------------------------------
  228. //    FW_CSelection::DoFindLinkSource
  229. //----------------------------------------------------------------------------------------
  230. FW_CLinkSource* FW_CSelection::DoFindLinkSource(Environment* ev)
  231. {
  232. FW_UNUSED(ev);
  233.     // Override to search for a link source corresponding to this selection
  234.     return NULL;
  235. }
  236.  
  237. //----------------------------------------------------------------------------------------
  238. //    FW_CSelection::GetSelectionInfoString
  239. //----------------------------------------------------------------------------------------
  240. FW_Boolean FW_CSelection::GetSelectionInfoString(Environment* ev, FW_CString& infoString)
  241. {
  242. FW_UNUSED(ev);
  243. FW_UNUSED(infoString);
  244.  
  245.     // Override to construct a string describing the selected data.
  246.     // By default return false, meaning we didn't return any information.
  247.     return false;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_CSelection::ShowSelectionInfo
  252. //----------------------------------------------------------------------------------------
  253. FW_Handled FW_CSelection::ShowSelectionInfo(Environment* ev)
  254. {
  255. FW_UNUSED(ev);
  256.     // Override to put up a dialog with information about the current selection.
  257.     return FW_kNotHandled;
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    FW_CSelection::CanEditSelection
  262. //----------------------------------------------------------------------------------------
  263. FW_Boolean FW_CSelection::CanEditSelection(Environment* ev, FW_CFrame* frame)
  264. {
  265.     FW_Boolean result = true;    // means OK to edit
  266.  
  267.     //--- Check the selection content to see if it's in a link managed by the part
  268.     FW_CLinkManager* linkMgr = GetPart(ev)->GetLinkManager(ev);
  269.     if (linkMgr)        // part supports linking
  270.     {
  271.         FW_Boolean multipleLinks = false;
  272.         FW_CLinkDestination* linkDest = this->GetLinkDestination(ev, multipleLinks);
  273.         if (linkDest)    // selection is in a single link destination
  274.         {
  275.             //--- Put up dialog asking user what to do
  276.             result = linkMgr->EditInLinkAlert(ev, linkDest, frame);
  277.         }
  278.         else if (multipleLinks)    // selection is in several link destinations
  279.         {
  280.             // Warn user about editing multiple links
  281.             GetPart(ev)->PrivShowErrorAlert(ev, FW_kLinkingStrings, FW_kMultipleLinksMsg);
  282.             result = false;
  283.         }
  284.     }
  285.  
  286.     return result;
  287. }
  288.  
  289. //----------------------------------------------------------------------------------------
  290. //    FW_CSelection::GetLinkDestination
  291. //----------------------------------------------------------------------------------------
  292. FW_CLinkDestination* FW_CSelection::GetLinkDestination(Environment* ev, FW_Boolean& multipleLinks)
  293. {
  294. FW_UNUSED(ev);
  295.     // Override to check for selected content being part of a link destination.
  296.     // If the selected content is in more than one link destination, set multipleLinks to true 
  297.     // and return NULL.
  298.     multipleLinks = false;
  299.     return NULL;
  300. }
  301.